//
//  ZCSTipsReTableViewCell.m
//  聆听FM
//
//  Created by dllo on 16/6/7.
//  Copyright © 2016年 Dark. All rights reserved.
//

#import "ZCSTipsReTableViewCell.h"

@implementation ZCSTipsReTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
- (void)setModel:(ZCSEditorReListModel *)model
{
    if (_model != model) {
        _model = model;
        [self.leftImageView sd_setImageWithURL:[NSURL URLWithString:model.albumCoverUrl290] placeholderImage:[UIImage sd_animatedGIFNamed:@"占位图"]];
        self.titleLabel.text = model.title;
        self.midLabel.text = model.trackTitle;
        if (model.playsCounts > 10000) {
            self.didCountLabel.text = [NSString stringWithFormat:@"%.1f万", model.playsCounts / 10000.0];
        }
        else
        {
            self.didCountLabel.text = [NSString stringWithFormat:@"%ld", model.playsCounts];
        }
        
        self.numberLabel.text = [NSString stringWithFormat:@"%ld集", model.tracks];
    }
}
- (void)setListenListModel:(ZCSListenListListModel *)listenListModel
{
    if (_listenListModel != listenListModel) {
        _listenListModel = listenListModel;
        [self.leftImageView sd_setImageWithURL:[NSURL URLWithString:listenListModel.albumCoverUrl290] placeholderImage:[UIImage sd_animatedGIFNamed:@"占位图"]];
        self.titleLabel.text = listenListModel.title;
        self.midLabel.text = listenListModel.intro;
        if (listenListModel.playsCounts > 10000) {
            self.didCountLabel.text = [NSString stringWithFormat:@"%.1f万", listenListModel.playsCounts / 10000.0];
        }
        else
        {
            self.didCountLabel.text = [NSString stringWithFormat:@"%ld", listenListModel.playsCounts];
        }
        
        self.numberLabel.text = [NSString stringWithFormat:@"%ld集", listenListModel.tracksCounts];
    }

}


- (void)setNewsListModel:(ZCSNewsCateListListModel *)newsListModel
{
    if (_newsListModel != newsListModel) {
        _newsListModel = newsListModel;
        [self.leftImageView sd_setImageWithURL:[NSURL URLWithString:newsListModel.albumCoverUrl290] placeholderImage:[UIImage sd_animatedGIFNamed:@"占位图"]];
        self.titleLabel.text = newsListModel.title;
        self.midLabel.text = newsListModel.trackTitle;
        if (newsListModel.playsCounts > 10000) {
            self.didCountLabel.text = [NSString stringWithFormat:@"%.1f万", newsListModel.playsCounts / 10000.0];
        }
        else
        {
            self.didCountLabel.text = [NSString stringWithFormat:@"%ld", newsListModel.playsCounts];
        }
        
        self.numberLabel.text = [NSString stringWithFormat:@"%ld集", newsListModel.tracks];
    }
}

- (void)setIntroduceAlbumsModel:(YWAnchorIntroduceAlbumsModel *)introduceAlbumsModel
{
    if (_introduceAlbumsModel != introduceAlbumsModel) {
        _introduceAlbumsModel = introduceAlbumsModel;
        [self.leftImageView sd_setImageWithURL:[NSURL URLWithString:introduceAlbumsModel.coverLarge] placeholderImage:[UIImage sd_animatedGIFNamed:@"占位图"]];
        _titleLabel.text = introduceAlbumsModel.title;
        
    
        //将数值转化为nsdate类型
        NSDate *beforeTime = [NSDate dateWithTimeIntervalSince1970:introduceAlbumsModel.updatedAt / 1000];
        //得到距1970时间差
        NSTimeInterval late = [beforeTime timeIntervalSince1970];
        //得到现在时间
        NSDate *now = [NSDate dateWithTimeIntervalSinceNow:0];
        //得到现在据1970时间差
        NSTimeInterval nowTo1970 = [now timeIntervalSince1970];
        //初始化时间差字符串
        NSString *timeString = @"";
        //发表距现在时间
        NSTimeInterval cha = nowTo1970 - late;
        //小于一小时
        if (cha / 3600 < 1) {
            timeString = [NSString stringWithFormat:@"%f", cha / 60];
            timeString = [timeString substringToIndex:timeString.length - 7];
            timeString=[NSString stringWithFormat:@"最后更新于%@分钟前", timeString];        }
        //小于一天
        if (cha / 3600 > 1 && cha / 86400 < 1) {
            timeString = [NSString stringWithFormat:@"%f", cha/3600];
            timeString =      [timeString substringToIndex:timeString.length-7];
            timeString = [NSString stringWithFormat:@"最后更新于%@小时前", timeString];
        }
        //大于一天
        if (cha / 86400 > 1 && cha / (3600 * 24 * 365) < 1)
        {
            timeString = [NSString stringWithFormat:@"%f", cha/86400];
            timeString = [timeString substringToIndex:timeString.length-7];
            timeString = [NSString stringWithFormat:@"最后更新于%@天前", timeString];
        }
        if (cha / (3600 * 24 * 365) > 1) {
            NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
            [formatter setDateFormat:@"yyyy-MM-dd HH-mm-ss"];
            timeString = [[formatter stringFromDate:beforeTime] substringToIndex:7];
            timeString = [NSString stringWithFormat:@"最后发布于%@", timeString];
        }
        _midLabel.text = timeString;
        NSInteger num = introduceAlbumsModel.playTimes;
        if (num < 10000) {
            _didCountLabel.text = [NSString stringWithFormat:@"%ld", num];
        }
        else
        {
            if (num % 10000 == 0) {
                _didCountLabel.text = [NSString stringWithFormat:@"%ld万", num / 10000];
            }
            _didCountLabel.text = [NSString stringWithFormat:@"%.f万", num / 10000.0];
        }
        _numberLabel.text = [NSString stringWithFormat:@"%ld集", introduceAlbumsModel.tracks];
    }
}

- (void)setSearchModel:(YWSearchModel *)searchModel
{
    if (_searchModel != searchModel) {
        _searchModel = searchModel;
        [self.leftImageView sd_setImageWithURL:[NSURL URLWithString:searchModel.cover_path] placeholderImage:[UIImage sd_animatedGIFNamed:@"占位图"]];
        _titleLabel.text = searchModel.title;
        _midLabel.text = searchModel.intro;
        NSInteger num = searchModel.play;
        if (num < 10000) {
            _didCountLabel.text = [NSString stringWithFormat:@"%ld", num];
        }
        else
        {
            if (num % 10000 == 0) {
                _didCountLabel.text = [NSString stringWithFormat:@"%ld万", num / 10000];
            }
            _didCountLabel.text = [NSString stringWithFormat:@"%.f万", num / 10000.0];
        }
        _numberLabel.text = [NSString stringWithFormat:@"%ld集", searchModel.tracks];
    }

}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
